
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<?php
		$output = isset($_POST['output']) ? $_POST['output'] : $_GET['output'];
		//$customer_id = isset($_POST['customer_id']) ? $_POST['customer_id'] : $_GET['customer_id'];
		if($output=="mark") print "<title>Mark point on map report</title>";
		else print "<title>View Map Report</title>";
?>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAX8eAnGdVGyiuBrhDTts0yxQmz3Fp_RbXKxUs78Cdg46fG8RfvhTkK9LW1OznsGE7UCEzN_W7FGFXaA" type="text/javascript"></script>

<!--<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAYRo9VK60DzqRHsBkppaFlRS_eW2k_STNLchqXsLMWCvAXNHBZRT_b4mM5Ff4mjtkoKAiF91eUDVAvg" type="text/javascript"></script>-->
<script src="getValue.js" type="text/javascript"></script>
<!--<script src="common.js" type="text/javascript"></script>-->
<script language=JavaScript src="color_picker/picker.js"></script>

    <style type="text/css">
      
      body {
        font-family: Verdana, Arial, sans serif;
        font-size: 11px;
        margin: 2px;
      }
	  .font1{
		font-family: Tahoma,Verdana, Arial, sans serif;
        font-size: 12px;
	  }
      table.directions th {
		background-color:#FFCC00;
      }
      img {
        color: #000000;
      }
	 DIV.body
		{
			BORDER-RIGHT: #808080 2px solid;
			PADDING-RIGHT: 1px;
			BORDER-TOP: #808080 2px solid;
			PADDING-LEFT: 1px;
			PADDING-BOTTOM: 1px;
			BORDER-LEFT: #808080 2px solid;
			COLOR: #000000;
			PADDING-TOP: 1px;
			BORDER-BOTTOM: #808080 2px solid;
			font-family: Tahoma, Verdana, Arial, sans serif, Tahoma;
			font-size: 12px;
			margin: 2px;
			HEIGHT: 80px;
			BACKGROUND-COLOR: #ffffff;
			TEXT-DECORATION: none
		}
	INPUT
		{
		font-family: Tahoma,  Arial, Helvetica, sans-serif; 
		font-size: 12px; 
		width: auto;
		font-weight: normal;
		/*background:none;*/
		border: 1px solid #000099; 
		}
	TEXTAREA
		{
		font-family: Tahoma, Arial, Helvetica, sans-serif; 
		font-size: 12px; 
		font-weight: normal;
		background:none;
		/*background-color: #EBEBEB;*/ 
		border: 1px solid #000099; 
		}
    </style>
	
<?php
		//if($output=="mark"){
?>
	<script>
	//--------------------- code check browser ajax ----------------------
		function Inint_AJAX() {
			try { return new ActiveXObject("Msxml2.XMLHTTP");    } catch(e) {}
			try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
			try { return new XMLHttpRequest();                   } catch(e) {}
			alert("XMLHttpRequest not supported");
			return null;
		}
		//-------------------------------------------------------------------------------

		function send() {
			var req = Inint_AJAX();
			var lat_mark=document.frmtest.lat.value;
			var lon_mark= document.frmtest.lon.value;
			var locatename=document.frmtest.locatename.value;
			var locatecode=document.frmtest.locatecode.value;
			var codecolor=document.frmtest.codecolor.value;
			var radius=document.frmtest.radius.value;
			var location_type=document.frmtest.location_type.value;
			var description=document.frmtest.description.value;

			var url ='markin_db.php?lat='+lat_mark+'&lon='+lon_mark+'&locatename='+locatename+'&locatecode='+locatecode+'&codecolor='+codecolor+'&radius='+radius+'&location_type='+location_type+'&description='+description;

			req.open('GET', url, true);
			req.onreadystatechange = function() {
					if (req.readyState==4) {
						if (req.status==200) {
							var ret=req.responseText;
							datas=ret.split(',')
							//แสดง error ถ้ามี
							document.getElementById("result").innerHTML=datas[0];
							document.frmtest.locatecode.value='MR-'+datas[1];
							document.frmtest.locatename.value='MarkR'+datas[1];
							//document.getElementById("status").innerHTML=data;
							//frm_send.seat.value="";
							//frm_send.user.value="";
						}
					}
			};
			req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); // set Header
			req.send(null);
		}
	</script>
	<script type="text/javascript">

    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		
		var plate ='test';//decode(getVar("plate"),"utf8");
		var locatename = 'test';//decode(getVar("locatename"),"utf8");//"";//
		var platename ='test'; //decode(getVar("plate_name"),"utf8");
		//var v_status = decode(getVar("vehicle_status"),"utf8");
		//var start_time = decode(getVar("start_time"),"utf8");
		//var stop_time = decode(getVar("stop_time"),"utf8");
		//var customer_id = decode(getVar("customer_id"),"utf8");
		//var difftime = decode(getVar("timediff"),"utf8");
		var lang ='th'; //decode(getVar("lang"),"utf8");
			
		/*var lat=getVar("lat");
		var lng=getVar("lon");*/
		var lat=13.842175;
		var lng=100.567915;
		var point = new GLatLng(lat,lng);
		var string_lat = point.lat();
		var string_lng = point.lng();
        map.setCenter(point, 13);
		 
		document.frmtest.lat.value=string_lat;
		document.frmtest.lon.value=string_lng;
		// <br><b></b>'++'
		//<br><b></b>'++'
		 if(lang=="th"){
			var WINDOW_HTML = '<div style="width: 250px; padding-right: 5px"><b>ทะเบียนรถ : </b>'+plate+' , <b>ชื่อเรียกรถ :  </b>'+platename+'<\/div>';
		}else{
			var WINDOW_HTML = '<div style="width: 250px; padding-right: 5px"><b>Plate No : </b>'+plate+' , <b>Vehicle :  </b>'+platename+'<\/div>';
		}

		 var marker = new GMarker(point, { draggable: true });

        GEvent.addListener(marker, "dragstart", function() {
          map.closeInfoWindow();
        });

        GEvent.addListener(marker, "dragend", function() {
		  var lat_lng = marker.getPoint();
		  var string_lat = lat_lng.lat();
		  var string_lng = lat_lng.lng();

		 document.frmtest.lat.value=string_lat;
		 document.frmtest.lon.value=string_lng;
		  if(lang=="th"){
			var WINDOW_HTML = '<div style="width: 250px; padding-right: 5px"><b>ทะเบียนรถ : </b>'+plate+' , <b>ชื่อเรียกรถ :  </b>'+platename+'<\/div>';
		}else{
			var WINDOW_HTML = '<div style="width: 250px; padding-right: 5px"><b>Plate No : </b>'+plate+' , <b>Vehicle :  </b>'+platename+'<\/div>';
		}
		 marker.openInfoWindowHtml(WINDOW_HTML);
        });

		 GEvent.addListener(marker, "click", function() {
		  var lat_lng = marker.getPoint();
		  var string_lat = lat_lng.lat();
		  var string_lng = lat_lng.lng();

		 document.frmtest.lat.value=string_lat;
		 document.frmtest.lon.value=string_lng;
		if(lang=="th"){
			var WINDOW_HTML = '<div style="width: 250px; padding-right: 5px"><b>ทะเบียนรถ : </b>'+plate+' , <b>ชื่อเรียกรถ :  </b>'+platename+'<\/div>';
		}else{
			var WINDOW_HTML = '<div style="width: 250px; padding-right: 5px"><b>Plate No : </b>'+plate+' , <b>Vehicle :  </b>'+platename+'<\/div>';
		}
		 marker.openInfoWindowHtml(WINDOW_HTML);
		});
        map.addOverlay(marker);
		marker.openInfoWindowHtml(WINDOW_HTML);
      }
    }  
    </script>
<?php
		//}//else{
			/*$btmenu = isset($_POST['btmenu']) ? $_POST['btmenu'] : $_GET['btmenu'];
			$locatecode = isset($_POST['locatecode']) ? $_POST['locatecode'] : $_GET['locatecode'];
			$locatename = isset($_POST['locatename']) ? $_POST['locatename'] : $_GET['locatename'];
			$customer_id = isset($_POST['customer_id']) ? $_POST['customer_id'] : $_GET['customer_id'];
			$code_color = isset($_POST['codecolor']) ? $_POST['codecolor'] : $_GET['codecolor'];
			$radius=isset($_POST['radius']) ? $_POST['radius'] : $_GET['radius'];
			$lat=isset($_POST['lat']) ? $_POST['lat'] : $_GET['lat'];
			$lng=isset($_POST['lon']) ? $_POST['lon'] : $_GET['lon'];
			$description=isset($_POST['description']) ? $_POST['description'] : $_GET['description'];
			$location_type=isset($_POST['location_type']) ? $_POST['location_type'] : $_GET['location_type'];
			$plate_name=isset($_POST['plate_name']) ? $_POST['plate_name'] : $_GET['plate_name'];

			/*$locatecode = isset($_POST['locate']) ? $_POST['locate'] : $_GET['locate'];
			$latitude = isset($_POST['lat']) ? $_POST['lat'] : $_GET['lat'];
			$longitude = isset($_POST['lon']) ? $_POST['lon'] : $_GET['lon'];
			$locatecode = isset($_POST['plate']) ? $_POST['plate'] : $_GET['plate'];
			$platename = isset($_POST['plate_name']) ? $_POST['plate_name'] : $_GET['plate_name'];
			$vehicle_status = isset($_POST['vehicle_status']) ? $_POST['vehicle_status'] : $_GET['vehicle_status'];
			$start_time = isset($_POST['start_time']) ? $_POST['start_time'] : $_GET['start_time'];
			$stop_time = isset($_POST['stop_time']) ? $_POST['stop_time'] : $_GET['stop_time'];
			$difftime = isset($_POST['timediff']) ? $_POST['timediff'] : $_GET['timediff'];
			$customer_id = isset($_POST['customer_id']) ? $_POST['customer_id'] : $_GET['customer_id'];*/
			
			/*if($location_type=="on") $location_type=1;
			else $location_type=0;
			if(intval($radius)==0) $radius=200;
			if(trim($description)==NULL) $description="NULL";
			
				//print $_REQUEST['location_type'];
			if($btmenu=="Save"){
				$table="locations";
				$dbflive="host=172.30.13.3 port=5423 dbname=fleetlive user=postgres password=";
				$dbconn_flive=pg_connect($dbflive);
		
				$sql="select check_box_position_th (".$lat.",".$lon.") as locate_th, check_box_position_en (".$lat.",".$lon.") as locate_en";
				$result = pg_query($dbconn_flive, $sql);
				$record = pg_fetch_array($result, 0, PGSQL_BOTH);
				$locate_th=$record["locate_th"];
				$locate_en=$record["locate_en"];
				pg_free_result($result);//, multi(buffer(geometryfromtext('point (".$lng." ".$lat.")', 4318 ),200))
				//multi(transform(buffer(transform(geometryfromtext('POINT(".$lng." ".$lat.")', 4318), 32647), ".$radius."), 4318))

				$sql_insert="insert into ".$table." (location_code, location_name, customer_id, location_description, location_geom, location_latitude, location_longitude, location_radius, location_type, location_position_en, location_position_th, location_color) values ('".$locatecode."','".$locatename."',".$customer_id.", '".$description."', multi(transform(buffer(transform(geometryfromtext('POINT(".$lng." ".$lat.")', 4318), 32647), ".$radius."), 4318)), ".$lat.", ".$lng.", ".$radius.", ".$location_type.", '".$locate_en."', '".$locate_th."', '".$code_color."')";	
		//print $sql_insert."<br>";
				$result=@pg_query($dbconn_flive, $sql_insert);
				if(!$result){
					$string_show="Not complete";
				}else $string_show="complete";
				pg_free_result($result);
				pg_close($dbconn_flive);
			}
		$latitude=$lat;
		$longitude=$lng;*/
?>
	<!--<script type="text/javascript">
    //<![CDATA[
		//javascript:window.close()
		//window.close();
    var map;
	//var box_code = getVar("box_code");
	var plate = decode(getVar("plate"),"utf8");
	var locatename = decode(getVar("locatename"),"utf8");//"";//
	var platename = decode(getVar("plate_name"),"utf8");
	var v_status = decode(getVar("vehicle_status"),"utf8");
	var start_time = decode(getVar("start_time"),"utf8");
	var stop_time = decode(getVar("stop_time"),"utf8");
	var difftime = decode(getVar("timediff"),"utf8");
	var lang = decode(getVar("lang"),"utf8");

	//var MyDate = new Date(start_time);
	//alert(MyDate.getTime());
	//var key_menu = getVar("keymenu");
	//var nameplate = decode(getVar("nameplate"),"utf8");
	//var namelocate = decode(getVar("namelocate"),"utf8");

	if(lang=="th"){
		var WINDOW_HTML = '<div style="width: 350px; padding-right: 5px"><b>ทะเบียนรถ : </b>'+plate+' <b>ชื่อเรียกรถ :  </b>'+platename+'<br><b>สถานที่ : </b> '+locatename+' <b>สถานะ : </b>'+v_status+'<br><b>วัน/เวลา : </b> '+start_time+' - '+stop_time+'<br><b>ระยะเวลา : </b> '+difftime+'<\/div>';
	}else{
		var WINDOW_HTML = '<div style="width: 350px; padding-right: 5px"><b>Plate No : </b>'+plate+' <b>Vehicle :  </b>'+platename+'<br><b>Location : </b>'+locatename+' <b>Status : </b>'+v_status+'<br><b>Date/Time : </b> '+start_time+' - '+stop_time+'<br><b>Duration : </b> '+difftime+'<\/div>';
	}

    function load() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		// Create our "tiny" marker icon
		var lat=getVar("lat");
		var lng=getVar("lon");
		var point = new GLatLng(lat,lng);
		map.setCenter(point,13);
		var marker = new GMarker(point);
       map.addOverlay(marker);
       GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(WINDOW_HTML);
      });
       marker.openInfoWindowHtml(WINDOW_HTML);
		//var icon = new GIcon();
		//icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		//icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		//icon.iconSize = new GSize(12, 20);
		//icon.shadowSize = new GSize(22, 20);
		//icon.iconAnchor = new GPoint(6, 20);
		//icon.infoWindowAnchor = new GPoint(5, 1);
		//var lat=getVar("lat");
		//var lng=getVar("lon");
		//var point = new GLatLng(lat,lng);
		//map.setCenter(point,13);
		//map.addOverlay(new GMarker(point, icon));
      }
    }
    
    //]]>
    </script>-->
<?php
		//}
?>
  </head>

  <body onload="load()" onunload="GUnload()">
<?php

			$lang_check = isset($_POST['lang']) ? $_POST['lang'] : $_GET['lang'];
			$mark_code=microtime();
			$mark_code=substr($mark_code, 2, 4);
			
			print $string_show."<br>";
			if($lang_check=="th"){
			//echo"<h2>".iconv("TIS-620","UTF-8","แสดงแผนที่")."</h2>";
				echo"<h2>กำหนดจุดตรวจสอบ</h2>";
				//print $sql_insert."<br>".$radius;
				//print $string_show;
			}else{
				echo"<h2>Mark Point Check</h2>";
				//print $sql_insert."<br>".$radius;
				//print $string_show;
			}
		//}

		/*if($output=="map"){
			echo "<form name=\"formexport\" action=\"pdfmap.php\" method=\"get\" target=\"_blank\">";
			echo "<input type=\"hidden\" name=\"lat\" value=\"".$lat."\">";
			echo "<input type=\"hidden\" name=\"lon\" value=\"".$lon."\">";
			echo "<input type=\"hidden\" name=\"plate\" value=\"".urlencode($plate)."\">";
			echo "<input type=\"hidden\" name=\"platename\" value=\"".urlencode($platename)."\">";
			echo "<input type=\"hidden\" name=\"location\" value=\"".urlencode($location)."\">";
			echo "<input type=\"submit\" name=\"btmenu\" value=\"Export PDF\">";
			echo"</form>";
		}*/
?>
    <br/>
 <table class="directions">

    <tr>
<?php
	if($lang_check=="th"){
		echo"<th align=\"left\">แผนที่</th><th align=\"left\">ฟอร์มรายละเอียดในการกำหนดจุด</th>";
	}else{
		echo"<th align=\"left\">Map</th><th align=\"left\">From detial check point</th>";
	}
?>
	</tr>
    <tr>
    <td valign="top"><div id="map" class="body" style="width: 480px; height: 470px"></div></td>
	<td valign="top">
	<div id="result"></div>
	<form name="frmtest">
	<table>
		<tr><td align="right"><b>Location code :</b></td><td align="left"><input type="text" name="locatecode" value="MR-<?php echo $mark_code; ?>"></td></tr>
		<tr><td align="right"><b>Location name :</b></td><td align="left"><input type="text" name="locatename" value="MarkR <?php echo $mark_code; ?>"></td></tr>
		<tr><td align="right"><b>Latitude :</b></td><td align="left"><input type="text" id="lat" name="lat" value="<?php echo $latitude; ?>" size="25" style="background:none;" readonly></td></tr>
		<tr><td align="right"><b>Longitude :</b></td><td align="left"><input type="text" id="lon" name="lon" value="<?php echo $longitude; ?>" size="25" style="background:none;" readonly></td></tr>
		<tr><td align="right"><b>Location color : </b></td><td align="left"><input type="text" name="codecolor" value="#FF9900" readonly>&nbsp;<a href="javascript:TCP.popup(document.forms['frmtest'].elements['codecolor'])"><img width="15" height="13" border="0" alt="Click Here to Pick up the color" src="color_picker/img/sel.gif" title="Click Here to Pick up the color"></a></td></tr>
		<tr><td align="right"><b>Redius [Metre(s)] : </b></td><td align="left"><input type="text" name="radius" value="200"></td></tr>
		<tr><td align="right"><b>Is check point : </b></td><td align="left"><input type="checkbox" name="location_type"></td></tr>
		<tr><td align="right" valign="top"><b>Description : </b></td><td align="left"><textarea name="description" cols="20" rows="4"></textarea></td></tr>
		<tr><td colspan="2" align="center">
		<input type="button" name="btmenu" value="Save" onclick="send()">&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" name="btmenu" value="Cancel"></tr>
	</table>
		<input type="hidden" name="customer_id" value="<?php echo $customer_id; ?>">
		<input type="hidden" name="start_time" value="<?php echo $start_time;?>">
		<input type="hidden" name="stop_time" value="<?php echo $stop_time;?>">
		<input type="hidden" name="timediff" value="<?php echo $difftime;?>">
		<input type="hidden" name="plate" value="<?php echo $plate;?>">
		<input type="hidden" name="lang" value="<?php echo $lang_check;?>">
		<input type="hidden" name="plate_name" value="<?php echo $plate_name;?>">
		<!--<input type="hidden" name="output" value="mark">-->
		<input type="hidden" name="vehicle_status" value="<?php echo $vehicle_status;?>">
	</form>
	</td>
    </tr>
    </table>
  </body>
</html>